package core.plugins.mycraft.cc;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.lang.reflect.Method;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.bukkit.craftbukkit.libs.jline.internal.Log;

import util.core.plugins.mycraft.cc.*;
import entity.core.plugins.mycraft.cc.Variabled;
import entity.core.plugins.mycraft.cc.config;
import entity.core.plugins.mycraft.cc.file;

public class test {
    static void test(Object tmp) {
        ((file) tmp).setName("aaa");
    }

    public static void main(String[] argv) {
        System.out.println("test");
        try {
            // 文件操作类
            FileOper fs = new FileOper("./resource/config.yml");
            // 配置文件加载类
            config cf = (config) new LoadBean(fs.fs, new config()).getVariabled();
            SQLOper ps = new SQLOper(cf);
            final String c = "CREATE TABLE test_for_use_sql( id int NOT NULL AUTO_INCREMENT PRIMARY KEY, name varchar(10), nick varchar(10), pass varchar(10))";  // create 
            // final String[] s = { "*", "test_for_use_sql","id{>}:i:","i{=}1",""};  // search
            final String[] s = { "*", "test_for_use_sql","","","0,10"};  // search
            //String[] s = { "*", "test_for_use_sql"};  // search
            final String[] i = { "test_for_use_sql", "name,nick,pass", "delovt1,admin1,1233"};  // insert
            final String[] u = {"test_for_use_sql","name {=} rbq,nick{=}test","id{!=}:i:","i{=}2"};  // update
            final String[] d = {"test_for_use_sql", "id{>}:i:,name{like}:n:","i{=}3,n{=}delovt%"};  // delete
            final String r = "DROP TABLE test_for_use_sql";  // drop
            
            //ps.CusExec("DROP TABLE IF EXISTS `test_for_use_sql`");
            //ps.CusExec(c);  // create            
            ps.Insert(new ArrayList<String>(Arrays.asList(i)));  // make insert
            //String[] a = {"NUM_ROWS","information_schema.INFODB_SYS_TABLESTATS","name{=}:n:","n{=}test/test_for_use_sql",""};
            //ps.Fetch(new ArrayList<String>(Arrays.asList(a)));
            //ResultSet rs = ps.getRs();
            //System.out.println(rs);
            /*int i1 = 1000;
            while(i1>0) {*/
                ps.FetchAll(new ArrayList<String>(Arrays.asList(s)));  // make search
                ResultSet rs = ps.getRs();
                 // get count
                 rs.last();
                 Log.info(rs.getRow());
                 rs.beforeFirst();
                while (rs.next()) {
                    Log.info(rs.getInt("id"),",",rs.getString("name"),",",rs.getString("nick"));
                }/*
                ps.Delete(new ArrayList<String>(Arrays.asList(d)));  // make delete
                ps.Update(new ArrayList<String>(Arrays.asList(u)));  // make update
                ps.FetchAll(new ArrayList<String>(Arrays.asList(s)));  // make search
                rs = ps.getRs();
                while (rs.next()) {
                    Log.info(rs.getInt("id"),",",rs.getString("name"),",",rs.getString("nick"));
                }
                i1--;
            }*/
            //ps.CusExec(r);  // drop
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        /*
         * File fs = new File("./MycraftPluginsCore/config.yml"); try { BufferedReader
         * reader = new BufferedReader(new FileReader(fs)); String line = null; int cot
         * = 0; Pattern p = Pattern.compile("\\S"); while((line = reader.readLine()) !=
         * null) { Matcher m = p.matcher(line); cot ++; while(m.find()) {
         * Log.info("Line: "+cot+" \t col: "+m.start()); } } } catch (Exception e) { //
         * TODO Auto-generated catch block e.printStackTrace(); }
         */

        // # ------------------ 动态生成对象 ----------------------
        // 创建自定义 map 对象
        /*
         * HashMap<String, Class> proper = new HashMap(); // 存入 信息 proper.put("name",
         * Class.forName("java.lang.String")); proper.put("path",
         * Class.forName("java.lang.String")); proper.put("suffix",
         * Class.forName("java.lang.String")); // 创建 bean 对象 并设置其值 file fs = new file();
         * DynamicBean bean = new DynamicBean(proper, fs); bean.setValue("name",
         * "delovt"); bean.setValue("path", "china no.1"); bean.setValue("suffix",
         * "test"); Object object = bean.getObject(); Class clazz = object.getClass();
         * Method[] methods = clazz.getDeclaredMethods(); for (Method curMethod:methods)
         * { Log.info(curMethod.getName()); } Log.info(clazz.getName()); try {
         * 
         * Log.info(fs.getClass().getName()); fs = (file) object;
         * Log.info(fs.getName()); } catch (Exception e) { // TODO Auto-generated catch
         * block e.printStackTrace(); }
         */

        // 反射类函数调用
        /*
         * Method m1 = herosClass.getMethod("setName",String.class); Method m2 =
         * herosClass.getMethod("getName"); Object userInfo = herosClass.newInstance();
         * m1.invoke(userInfo,"影魔"); System.out.println("调用set方法："+userInfo);
         * System.out.println("调用get方法："+m2.invoke(userInfo));
         */
    }
}
